package com.hdu.hot100.hash;

import java.util.HashMap;
import java.util.Map;

public class lc01 {
    class Solution {
        public int[] twoSum(int[] nums, int target) {
            Map<Integer, Integer> num2index = new HashMap<>();
            for (int i = 0; i < nums.length; i++) {
                int num = nums[i];
                int complement = target - num;
                if (num2index.containsKey(complement)) {
                    return new int[]{num2index.get(complement), i};
                }
                num2index.put(num, i);
            }
            return null;
        }
    }
}
